define(['jquery', 'bootstrap', 'backend', 'table', 'form','cookie', 'editable'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wu/procedurestatelog/index',
                    add_url: 'wu/procedurestatelog/add',
                    edit_url: 'wu/procedurestatelog/edit',
                    del_url: 'wu/procedurestatelog/del',
                    multi_url: 'wu/procedurestatelog/multi',
                    table: 'wu_procedurestatelog',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showExport: false,
                searchFormVisible: true,
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},
                        {
                            field: 'procedure.name',
                            title: __('工序名稱'),
                            searchList: Config.proceduretypeList,
                            formatter: Table.api.formatter.normal
                        },
                        {field: 'workorder.ordernumber', title: __('製令單號')},
                        {field: 'spectypename', title: __('產品類型'), operate:false, formatter: Table.api.formatter.normal},
                        {field: 'workorder.spectype_id', title: __('產品類型'), visible: false, addClass: "selectpage", extend: "data-source='wu/spectype/index' data-field='name'"},
                        {field: 'workorder.ProductName', title: __('產品名稱'), operate:false},
                        {field: 'workorder.num', title: __('生產數量'), operate:false},
                        {field: 'msg', title: __('執行工作'), operate:false},
                        {field: 'man.name', title: __('工作人員'), operate:false},
                        {field: 'num', title: __('確認數量'), operate:false},

                        //{field: 'procedurestate_id', title: __('Procedurestate_id')},
                        //{field: 'jt.name', title: __('Jt.name'), operate:false},
                        //{field: 'man_id', title: __('Man_id')},
                        //{field: 'jt_id', title: __('Jt_id')},
                        //{field: 'productspec_id', title: __('Productspec_id')},
                        //{field: 'productspec.name', title: __('Productspec.name'), operate:false},
                        //{field: 'workorder_id', title: __('Workorder_id')},
                        //{field: 'procedure_id', title: __('Procedure_id')},
                        {
                            field: 'msg',
                            title: __('備註*'),
                            editable: {
                                emptytext: '无',
                                rows:10,
                                tpl: "<textarea rows='10' cols='50'></textarea>",
                                success: function (response, newValue) {
                                    //$(".btn-refresh").trigger("click");
                                }
                            },
                            operate: false,
                            align: 'left',
                        },
                        {field: 'wggs_str', title: __('完工工時'), operate:false},
                        {
                            field: 'dggs',
                            title: __('單根工時(秒)'),
                            editable: {
                                emptytext: '无',
                                rows:10,
                                tpl: "<textarea rows='10' cols='50'></textarea>",
                                success: function (response, newValue) {
                                    //$(".btn-refresh").trigger("click");
                                }
                            },
                            operate: false,
                            align: 'left',
                        },
                        //{field: 'state', title: __('State'), searchList: {"0":__('State 0'),"1":__('State 1')}, formatter: Table.api.formatter.normal},
                        //{field: 'type', title: __('Type'), searchList: {"0":__('Type 0'),"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'create_time', title: __('執行日期'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'jt.id', title: __('Jt.id')},

                        //{field: 'jt.number', title: __('Jt.number')},
                        //{field: 'jt.state', title: __('Jt.state')},
                        //{field: 'jt.testhours', title: __('Jt.testhours'), operate:'BETWEEN'},
                        //{field: 'jt.byjxdate', title: __('Jt.byjxdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'jt.usehours', title: __('Jt.usehours'), operate:'BETWEEN'},
                        //{field: 'jt.create_time', title: __('Jt.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'jt.update_time', title: __('Jt.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'jt.proceduretype_id', title: __('Jt.proceduretype_id')},
                        //{field: 'productspec.id', title: __('Productspec.id')},
                        //{field: 'productspec.spectype_id', title: __('Productspec.spectype_id')},
                        //{field: 'productspec.specnumber', title: __('Productspec.specnumber')},
                        //{field: 'productspec.nbznumber', title: __('Productspec.nbznumber')},
                        //{field: 'productspec.lycl', title: __('Productspec.lycl')},
                        //{field: 'productspec.bztb', title: __('Productspec.bztb')},
                        //{field: 'productspec.create_time', title: __('Productspec.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'productspec.update_time', title: __('Productspec.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'workorder.id', title: __('Workorder.id')},
                        //{field: 'workorder.productspec_id', title: __('Workorder.productspec_id')},
                        //{field: 'workorder.orderdate', title: __('Workorder.orderdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'workorder.name', title: __('Workorder.name')},
                        //{field: 'workorder.ordernumber', title: __('Workorder.ordernumber')},
                        //{field: 'workorder.type', title: __('Workorder.type')},
                        //{field: 'workorder.startdate', title: __('Workorder.startdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'workorder.finishdate', title: __('Workorder.finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'workorder.num', title: __('Workorder.num')},
                        //{field: 'workorder.ProductName', title: __('Workorder.productname')},
                        //{field: 'workorder.danhao', title: __('Workorder.danhao')},
                        //{field: 'workorder.lystate', title: __('Workorder.lystate')},
                        //{field: 'workorder.lbnumber', title: __('Workorder.lbnumber')},
                        //{field: 'workorder.create_time', title: __('Workorder.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'workorder.update_time', title: __('Workorder.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'procedure.id', title: __('Procedure.id')},
                        //{field: 'procedure.productspec_id', title: __('Procedure.productspec_id')},
                        //{field: 'procedure.name', title: __('Procedure.name')},
                        //{field: 'procedure.procedurenumber', title: __('Procedure.procedurenumber')},
                        //{field: 'procedure.manhours', title: __('Procedure.manhours'), operate:'BETWEEN'},
                        //{field: 'procedure.order', title: __('Procedure.order')},
                        //{field: 'procedure.typenumber', title: __('Procedure.typenumber')},
                        //{field: 'procedure.create_time', title: __('Procedure.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'procedure.update_time', title: __('Procedure.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'procedurestate.id', title: __('Procedurestate.id')},
                        //{field: 'procedurestate.planlog_id', title: __('Procedurestate.planlog_id')},
                        //{field: 'procedurestate.procedure_id', title: __('Procedurestate.procedure_id')},
                        //{field: 'procedurestate.man_id', title: __('Procedurestate.man_id')},
                        //{field: 'procedurestate.order', title: __('Procedurestate.order')},
                        //{field: 'procedurestate.num0', title: __('Procedurestate.num0')},
                        //{field: 'procedurestate.num1', title: __('Procedurestate.num1')},
                        //{field: 'procedurestate.state', title: __('Procedurestate.state')},
                        //{field: 'procedurestate.startdate', title: __('Procedurestate.startdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'procedurestate.enddate', title: __('Procedurestate.enddate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'procedurestate.createtime', title: __('Procedurestate.createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'procedurestate.updatetime', title: __('Procedurestate.updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        ////{field: 'man.id', title: __('Man.id')},
                        //{field: 'man.admin_id', title: __('Man.admin_id')},
                        //{field: 'man.name', title: __('Man.name')},
                        //{field: 'man.number', title: __('Man.number')},
                        //{field: 'man.state', title: __('Man.state')},
                        //{field: 'man.proceduretype1_id', title: __('Man.proceduretype1_id')},
                        //{field: 'man.proceduretype2_id', title: __('Man.proceduretype2_id')},
                        //{field: 'man.proceduretype3_id', title: __('Man.proceduretype3_id')},
                        //{field: 'man.proceduretype4_id', title: __('Man.proceduretype4_id')},
                        //{field: 'man.proceduretype5_id', title: __('Man.proceduretype5_id')},
                        //{field: 'man.proceduretype6_id', title: __('Man.proceduretype6_id')},
                        //{field: 'man.proceduretype7_id', title: __('Man.proceduretype7_id')},
                        //{field: 'man.proceduretype8_id', title: __('Man.proceduretype8_id')},
                        //{field: 'man.proceduretype9_id', title: __('Man.proceduretype9_id')},
                        //{field: 'man.proceduretype10_id', title: __('Man.proceduretype10_id')},
                        //{field: 'man.create_time', title: __('Man.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'man.update_time', title: __('Man.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 选择隐藏字段事件，使用cookie存入
            table.on('column-switch.bs.table', function (e, json) {
                    var myColumns=[];
                    $.each(table.bootstrapTable('getHiddenColumns'), function(i, item) {
                         myColumns.push(item.field);
                    });
                    $.cookie('fa_wu_procedurestatelog', JSON.stringify(myColumns), { expires: 365, path: '/'});
             });
             if($.cookie('fa_wu_procedurestatelog')){
                //读取cookie隐藏字段
                $.each(JSON.parse($.cookie('fa_wu_procedurestatelog')), function(i, item) {
                  table.bootstrapTable('hideColumn', item);
                });
             }

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        index2: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wu/procedurestatelog/index2',
                    add_url: 'wu/procedurestatelog/add',
                    edit_url: 'wu/procedurestatelog/edit',
                    del_url: 'wu/procedurestatelog/del',
                    multi_url: 'wu/procedurestatelog/multi',
                    table: 'wu_procedurestatelog',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                search:false,
                showToggle: false,
                showExport: false,
                searchFormVisible: true,
                columns: [
                    [
                        //{checkbox: true},
                        {field: 'id', title: __('Id'), operate:false},
                        {
                            field: 'procedure.name',
                            title: __('工序名稱'),
                            searchList: Config.proceduretypeList,
                            formatter: Table.api.formatter.normal
                        },
                        {field: 'workorder.ordernumber', title: __('製令單號')},
                        {field: 'spectypename', title: __('產品類型'), operate:false, formatter: Table.api.formatter.normal},
                        {field: 'workorder.spectype_id', title: __('產品類型'), visible: false, addClass: "selectpage", extend: "data-source='wu/spectype/index' data-field='name'"},
                        {field: 'workorder.ProductName', title: __('產品名稱'), operate:false},
                        {field: 'workorder.num', title: __('生產數量'), operate:false},
                        {field: 'msg', title: __('執行工作'), operate:false},
                        {field: 'man.name', title: __('工作人員'), operate:false},
                        {field: 'num', title: __('完工數量'), operate:false},
                        {field: 'wggs_str', title: __('完工工時'), operate:false},
                        {
                            field: 'dggs',
                            title: __('單根工時(秒)'),
                            editable: {
                                emptytext: '无',
                                rows:10,
                                tpl: "<textarea rows='10' cols='50'></textarea>",
                                success: function (response, newValue) {
                                    //$(".btn-refresh").trigger("click");
                                }
                            },
                            operate: false,
                            align: 'left',
                        },
                        //{field: 'snum', title: __('損耗數量'), operate:false},
                        //{
                        //    field: 'msg',
                        //    title: __('損耗備註*'),
                        //    editable: {
                        //        emptytext: '无',
                        //        rows:10,
                        //        tpl: "<textarea rows='10' cols='50'></textarea>",
                        //        success: function (response, newValue) {
                        //            //$(".btn-refresh").trigger("click");
                        //        }
                        //    },
                        //    operate: false,
                        //    align: 'left',
                        //},
                        //{field: 'state', title: __('State'), searchList: {"0":__('State 0'),"1":__('State 1')}, formatter: Table.api.formatter.normal},
                        //{field: 'type', title: __('Type'), searchList: {"0":__('Type 0'),"1":__('Type 1'),"2":__('Type 2'),"3":__('Type 3')}, formatter: Table.api.formatter.normal},
                        {field: 'create_time', title: __('執行日期'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'update_time', title: __('Update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'jt.id', title: __('Jt.id')},

                        //{field: 'jt.number', title: __('Jt.number')},
                        //{field: 'jt.state', title: __('Jt.state')},
                        //{field: 'jt.testhours', title: __('Jt.testhours'), operate:'BETWEEN'},
                        //{field: 'jt.byjxdate', title: __('Jt.byjxdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'jt.usehours', title: __('Jt.usehours'), operate:'BETWEEN'},
                        //{field: 'jt.create_time', title: __('Jt.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'jt.update_time', title: __('Jt.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'jt.proceduretype_id', title: __('Jt.proceduretype_id')},
                        //{field: 'productspec.id', title: __('Productspec.id')},
                        //{field: 'productspec.spectype_id', title: __('Productspec.spectype_id')},
                        //{field: 'productspec.specnumber', title: __('Productspec.specnumber')},
                        //{field: 'productspec.nbznumber', title: __('Productspec.nbznumber')},
                        //{field: 'productspec.lycl', title: __('Productspec.lycl')},
                        //{field: 'productspec.bztb', title: __('Productspec.bztb')},
                        //{field: 'productspec.create_time', title: __('Productspec.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'productspec.update_time', title: __('Productspec.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'workorder.id', title: __('Workorder.id')},
                        //{field: 'workorder.productspec_id', title: __('Workorder.productspec_id')},
                        //{field: 'workorder.orderdate', title: __('Workorder.orderdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'workorder.name', title: __('Workorder.name')},
                        //{field: 'workorder.ordernumber', title: __('Workorder.ordernumber')},
                        //{field: 'workorder.type', title: __('Workorder.type')},
                        //{field: 'workorder.startdate', title: __('Workorder.startdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'workorder.finishdate', title: __('Workorder.finishdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'workorder.num', title: __('Workorder.num')},
                        //{field: 'workorder.ProductName', title: __('Workorder.productname')},
                        //{field: 'workorder.danhao', title: __('Workorder.danhao')},
                        //{field: 'workorder.lystate', title: __('Workorder.lystate')},
                        //{field: 'workorder.lbnumber', title: __('Workorder.lbnumber')},
                        //{field: 'workorder.create_time', title: __('Workorder.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'workorder.update_time', title: __('Workorder.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'procedure.id', title: __('Procedure.id')},
                        //{field: 'procedure.productspec_id', title: __('Procedure.productspec_id')},
                        //{field: 'procedure.name', title: __('Procedure.name')},
                        //{field: 'procedure.procedurenumber', title: __('Procedure.procedurenumber')},
                        //{field: 'procedure.manhours', title: __('Procedure.manhours'), operate:'BETWEEN'},
                        //{field: 'procedure.order', title: __('Procedure.order')},
                        //{field: 'procedure.typenumber', title: __('Procedure.typenumber')},
                        //{field: 'procedure.create_time', title: __('Procedure.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'procedure.update_time', title: __('Procedure.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'procedurestate.id', title: __('Procedurestate.id')},
                        //{field: 'procedurestate.planlog_id', title: __('Procedurestate.planlog_id')},
                        //{field: 'procedurestate.procedure_id', title: __('Procedurestate.procedure_id')},
                        //{field: 'procedurestate.man_id', title: __('Procedurestate.man_id')},
                        //{field: 'procedurestate.order', title: __('Procedurestate.order')},
                        //{field: 'procedurestate.num0', title: __('Procedurestate.num0')},
                        //{field: 'procedurestate.num1', title: __('Procedurestate.num1')},
                        //{field: 'procedurestate.state', title: __('Procedurestate.state')},
                        //{field: 'procedurestate.startdate', title: __('Procedurestate.startdate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'procedurestate.enddate', title: __('Procedurestate.enddate'), operate:'RANGE', addclass:'datetimerange'},
                        //{field: 'procedurestate.createtime', title: __('Procedurestate.createtime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'procedurestate.updatetime', title: __('Procedurestate.updatetime'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        ////{field: 'man.id', title: __('Man.id')},
                        //{field: 'man.admin_id', title: __('Man.admin_id')},
                        //{field: 'man.name', title: __('Man.name')},
                        //{field: 'man.number', title: __('Man.number')},
                        //{field: 'man.state', title: __('Man.state')},
                        //{field: 'man.proceduretype1_id', title: __('Man.proceduretype1_id')},
                        //{field: 'man.proceduretype2_id', title: __('Man.proceduretype2_id')},
                        //{field: 'man.proceduretype3_id', title: __('Man.proceduretype3_id')},
                        //{field: 'man.proceduretype4_id', title: __('Man.proceduretype4_id')},
                        //{field: 'man.proceduretype5_id', title: __('Man.proceduretype5_id')},
                        //{field: 'man.proceduretype6_id', title: __('Man.proceduretype6_id')},
                        //{field: 'man.proceduretype7_id', title: __('Man.proceduretype7_id')},
                        //{field: 'man.proceduretype8_id', title: __('Man.proceduretype8_id')},
                        //{field: 'man.proceduretype9_id', title: __('Man.proceduretype9_id')},
                        //{field: 'man.proceduretype10_id', title: __('Man.proceduretype10_id')},
                        //{field: 'man.create_time', title: __('Man.create_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'man.update_time', title: __('Man.update_time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        //{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 选择隐藏字段事件，使用cookie存入
            table.on('column-switch.bs.table', function (e, json) {
                var myColumns=[];
                $.each(table.bootstrapTable('getHiddenColumns'), function(i, item) {
                    myColumns.push(item.field);
                });
                $.cookie('fa_wu_procedurestatelog', JSON.stringify(myColumns), { expires: 365, path: '/'});
            });
            if($.cookie('fa_wu_procedurestatelog')){
                //读取cookie隐藏字段
                $.each(JSON.parse($.cookie('fa_wu_procedurestatelog')), function(i, item) {
                    table.bootstrapTable('hideColumn', item);
                });
            }

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});